package com.example.pptls;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Toast;



public class ListenerBoton implements OnClickListener,OnCheckedChangeListener{

	private String user1,user2;
	private MainActivity a;
	private Activity act;
	public ListenerBoton(Activity act, String user1, String user2){
		this.act=act;
		this.user1=user1;
		this.user2=user2;
	}
	
	public ListenerBoton(Activity act){
		this.act = act;
		
	}
	public ListenerBoton(MainActivity a){
		this.a = a;
		
	}
	@Override
	public void onClick(View v) {
	
		switch(v.getId()){
		case R.id.botAceptar1:
			avanzarPrimera();
			break;
			
		case R.id.bVolver:
			volverAjugar();
			break;
			
		case R.id.bFin:
			
			Intent inte = new Intent(act, MainActivity.class);
			act.startActivity(inte);
			act.finish();
			break;
			
			
			
		case R.id.botSql:
			
			Intent inte1 = new Intent(act, MainActivity.class);
			act.startActivity(inte1);
			act.finish();
			break;
		
			
		case R.id.botXML:
			
			Intent inte2 = new Intent(act, MainActivity.class);
			act.startActivity(inte2);
			act.finish();
			break;
		
			
		case R.id.botBin:
			
			Intent inte3 = new Intent(act, MainActivity.class);
			act.startActivity(inte3);
			act.finish();
			break;
		}
		
	
			
	
	}

	
	private void volverAjugar(){
		
		Intent intent = new Intent(act, Primera.class);
		intent.putExtra("modoJuego", "1");
		intent.putExtra("nombreUser1",user1);
		intent.putExtra("nombreUser2",user2);
		
		act.startActivity(intent);
		act.finish();
	}
	private void avanzarPrimera(){
	
		String j1 = a.getEdt().getText().toString();
		
		String aux = String.valueOf(a.getModojuego());
		
		if(a.getModojuego()==1){
			
			if(j1.equals("")){
				Toast.makeText(a,"Introduce un nombre de usuario", Toast.LENGTH_SHORT).show();
			}else{
				Intent intent = new Intent(a, Primera.class);
				intent.putExtra("modoJuego", aux);
				intent.putExtra("nombreUser1",j1);
				intent.putExtra("nombreUser2", "Sheldon");
				a.startActivity(intent);
				//a.finish();
				}	
		}
			else{
				String j2 = a.getEdt2().getText().toString();
				
				if(j2.equals("")){
					Toast.makeText(a,"Introduce un nombre de usuario", Toast.LENGTH_SHORT).show();
				}else{
					Intent intent = new Intent(a, Primera.class);
					intent.putExtra("modoJuego", aux);
					intent.putExtra("nombreUser1",j1);
					intent.putExtra("nombreUser2",j2);
					a.startActivity(intent);
					//a.finish();
				}
				
			}
		
	}
	@Override
	public void onCheckedChanged(RadioGroup rg, int arg1) {

		if(rg.getCheckedRadioButtonId()==R.id.radio1){
			a.getEdt2().setEnabled(true);
			a.setModojuego(2);
		}
			
		else{
			a.getEdt2().setEnabled(false);
			a.setModojuego(1);
		}
		


	}
	
}
